package com.ksyun.whgc.liweiliang.work3;

/**
 * @Deseription
 * @Author lwl
 * @Date 2023/4/19 9:10
 */
public class PrintB implements Runnable{

    private String name;
    private Num num;
    private int flag;

    PrintB(){}
    PrintB(String name,Num num,int flag){
        this.name = name;
        this.num = num;
        this.flag = flag;
    }


    @Override
    public void run() {
        Thread.currentThread().setName(name);
        int count = 0;

        while(count < flag) {

            synchronized (num) {

                if (num.num % 3 == 1) {
                    System.out.print(Thread.currentThread().getName());
                    count++;
                    num.num ++;
                    num.notifyAll();

                    try {
                        num.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
        }
    }
}
